/* GUI CONVERTED from rcslcmt.p (converter v1.76) Mon Jul 30 07:02:34 2001 */
/* rcslcmt.p - SALES ORDER LINE CHARGE DATA  MAINTENANCE              */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                */
/* All rights reserved worldwide.  This is an unpublished work.       */
/* $Revision: 1.7 $                                                   */
/*                                                                    */
/* This program allows access to a sales order or a scheduled order's */
/* additional line charges were they can be modified.                 */
/* Modification to the header or line item detail, is not allowed     */
/* from this program.                                                 */
/*                                                                    */
/* $Revision: 1.7 $    BY: Dan Herman   DATE: 07/16/01   ECO: *P006*  */
/*V8:ConvertMode=Maintenance                                            */
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */

{mfdtitle.i "b+ "}

{pxpgmmgr.i}

define variable vAddr like ad_addr no-undo.

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
so_site         colon 11 label "Ship-From"
   so_nbr            at 37
   so_ship         colon 11
   ad_name           at 37 no-label
 SKIP(.4)  /*GUI*/
with frame so width 80 attr-space side-labels NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-so-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame so = F-so-title.
 RECT-FRAME-LABEL:HIDDEN in frame so = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame so =
  FRAME so:HEIGHT-PIXELS - RECT-FRAME:Y in frame so - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME so = FRAME so:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame so:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
sod_part             colon 11 label "Item"
   sod_desc             at 37 no-label
   pt_um                colon 72
   sod_custpart         at 37 no-label format "x(28)"
   sod_line             colon 72
 SKIP(.4)  /*GUI*/
with frame sod width 80 attr-space side-labels NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-sod-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame sod = F-sod-title.
 RECT-FRAME-LABEL:HIDDEN in frame sod = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame sod =
  FRAME sod:HEIGHT-PIXELS - RECT-FRAME:Y in frame sod - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME sod = FRAME sod:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame sod:handle).

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   find first soc_ctrl no-lock.
   hide frame sod.

   block_1:
   do with frame so:
      prompt-for so_site
         so_ship
         so_nbr
         editing:
         {mfnp08.i so_mstr
            so_nbr
            true
            so_site "input so_site"
            so_ship "input so_ship"
            so_nbr  "input so_nbr"}

         if recno <> ? then do:
            for first si_mstr fields(si_site si_db) no-lock
               where si_site = so_site:
            end.
            for first ad_mstr fields(ad_name ad_addr) no-lock
               where ad_addr = so_ship:
            end.

            display
               so_site
               so_ship
               ad_name  when (available ad_mstr)
               so_nbr.
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* EDITING */

      /* FIND EXISTING ORDER INFO IF IT EXISTS */
      if input so_nbr <> "" then do:
         for first so_mstr fields(so_nbr so_site so_ship so_conrep) no-lock
            where so_nbr = input so_nbr:
         end.

         if available so_mstr then
         display
            so_site
            so_ship
         with frame so.
      end.

      /* VALIDATE */
      for first si_mstr fields(si_site si_db) no-lock
         where si_site = input so_site:
      end.

      if not available si_mstr then do:
         {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}
         /* SITE DOES NOT EXIST */
         undo, retry.
      end.

      {gprun.i ""gpsiver.p""
         "(input si_site, input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if return_int = 0 then do:
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         /* USER DOES NOT HAVE ACCESS TO SITE */
         undo, retry.
      end.

      /* IF NOT CONNECTED, ISSUE ERROR AND UNDO */
      if si_db <> global_db
         and not connected(si_db) then do:
         {pxmsg.i &MSGNUM=2510 &ERRORLEVEL=4 &MSGARG1=si_db}
         /* DATABASE NOT CONNECTED */
         undo, retry.
      end.

      for first ad_mstr fields(ad_name ad_addr) no-lock
         where ad_addr = input so_ship:
      end.
      if not available ad_mstr then do:
         {pxmsg.i &MSGNUM=8501 &ERRORLEVEL=3}
         /* SHIP-TO DOES NOT EXIST */
         undo, retry.
      end.

      for first ls_mstr fields(ls_addr ls_type) no-lock
         where ls_addr = ad_addr
         and (ls_type = "customer" or ls_type = "ship-to"
         or ls_type = "dock"):
      end.

      if not available ls_mstr then do:
         {pxmsg.i &MSGNUM=8156 &ERRORLEVEL=3}
         /* INVALID CUSTOMER OR SHIP-TO */
         undo, retry.
      end.

      for first cm_mstr fields(cm_addr) no-lock
         where cm_addr = ad_addr:
      end.

      do while not available cm_mstr and ad_ref <> "":
         vAddr = ad_ref.
         for first ad_mstr fields(ad_name ad_addr) no-lock
            where ad_addr = vAddr:
         end.
         for first cm_mstr fields(cm_addr) no-lock
            where cm_addr = ad_addr:
         end.
      end.

      for first ad_mstr fields(ad_name ad_addr) no-lock
         where ad_addr = input so_ship:
      end.

      display
         ad_name.

      for first so_mstr fields(so_nbr so_site so_ship so_conrep) no-lock
         where so_nbr = input so_nbr:
      end.

      if not available so_mstr then do:
         {pxmsg.i &MSGNUM=6010 &ERRORLEVEL=3}
         /* ORDER DOES NOT ESXIST */
         undo, retry.
      end.

      /* MUST BE IN ORDER DATABASE*/
      if trim(substring(so_conrep,15,20)) <> global_db then do:
         {pxmsg.i &MSGNUM=8148
            &ERRORLEVEL=3
            &MSGARG1=trim(substring(so_conrep,15))}
         undo, retry.
      end.

   end. /*end of block_1 */
   view frame sod.

   block_2:
   repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

      do with frame sod:
         prompt-for sod_part
            sod_line
            editing:
            {mfnp08.i sod_det
               sod_part
               "sod_nbr = so_nbr"
               sod_nbr so_nbr
               sod_part sod_part
               sod_line sod_line}

            if recno <> ? then do:
               for first pt_mstr fields(pt_part pt_um) no-lock
                  where pt_part = sod_part:
               end.
               display
                  sod_part
                  sod_line
                  sod_desc
                  sod_custpart
                  pt_um when (available pt_mstr).
            end.
         end. /* EDITING */

         /* FIND EXISTING ORDER INFO IF IT EXISTS */
         if input sod_part > "" then do:
            for first sod_det
               fields(sod_nbr sod_part sod_line
                      sod_desc sod_custpart) no-lock
               where sod_nbr = so_nbr
               and sod_part = input sod_part:
            end.
         end.
         else
            if input sod_line > 0 then do:
            for first sod_det
               fields(sod_nbr sod_part sod_line
                      sod_desc sod_custpart) no-lock
               where sod_nbr = so_nbr
               and sod_line = input sod_line:
            end.
         end.

         if available sod_det then do:
            for first pt_mstr fields(pt_part pt_um) no-lock
               where pt_part = sod_part:
            end.
            display
               sod_part
               sod_line
               sod_desc
               sod_custpart
               pt_um when (available pt_mstr).
         end.

         if not available sod_det then do:
            /*ORDER LINE DOES NOT EXIST */
            {pxmsg.i &MSGNUM=6011 &ERRORLEVEL=3}
            undo, retry.
         end.

         {gprun.i ""rcsolcmt.p""
            "(input recid(so_mstr),
                       input recid(sod_det))"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end. /*DO WITH FRAME SOD */
   end. /* END BLOCK_2 REPEAT */
end. /* MAINLOOP */
